import pandas as pd
import time
from math import radians, cos, sin, asin, sqrt
import csv
s_time=time.time()
time=(s_time+8*3600)/86400+70*365+19
print(time)
# t_tamp = 1462451334

#显示所有列
pd.set_option('display.max_columns', None)
#显示所有行
pd.set_option('display.max_rows', None)
#
data = pd.read_csv('gps_20161003', sep = ',', header = None, names = ['DriverID', 'OrderID', 'timestamp','longitude','dimensionality'])
# print(data.head(10))
d=data.groupby(['DriverID','OrderID'])

D=d.min().reset_index()
D.to_csv('../Data/xian/Mintime',sep='\t',header=False,index=None)

W=d.max().reset_index()
W.to_csv('../Data/xian/Maxtime',sep='\t',header=False,index=None)




 #转换成新的时间格式(2016-05-05 20:28:54)
# data.eval('time = (timestamp+8*3600)/86400+70*365+19', inplace = True)
#添加订单价格（工人可得到的报酬金额）
# data.eval()

# print(type(data))
# print(data.columns)
# data.columns.tolist()
# print(data.dtypes)
# file = data.head(20)
# print(file)
# 找出不重复的orderid
data = data.drop_duplicates(['DriverID'],keep='first',inplace=False)
#保存
data.to_csv(path_or_buf='~/Downloads/Xianshi/DriverID.csv', sep=',', na_rep='', float_format=None, columns=['DriverID', ], header=True, index=None,
                 index_label=None, mode='w', encoding=None, compression=None, quoting=None, quotechar='"',
                 line_terminator='\n', chunksize=None, date_format=None, doublequote=True,
                 escapechar=None, decimal='.')
#
# # 遍历文件找出同一个订单中时间最大的行
# OrderID = pd.read_csv('~/Downloads/Xianshi/DriverID.csv', sep = ',', header = None, names = ['OrderID'])
#
# file = open('gps_20161001','r')
# lines = file.readlines()  #使用readlines()函数 读取文件的全部内容，存成一个列表，每一项都是以换行符结尾的一个字符串，对应着文件的一行
#
# list_DriverID = []  #初始化一个空列表 用来存该文件的司机ID 也就是第一列
# list_OrderID = []
# list_timestamp = []
# list_longitude = []
# list_dimensionality = []
#
# for line in lines:     #开始进行处理 把第一列存到list_DriverID 第二列存到list_OrderID,,,,,
#     elements=line.split(',')
#     list_DriverID.append(elements[0])
#     list_OrderID.append(elements[1])
#     list_timestamp.append(elements[2])
#     list_longitude.append(elements[3])
#     list_dimensionality.append(elements[4])
#
# index = 0
# i = 1
# j=0
# index = 0
# max_time = 0
# min_time = 999999999999
# isFind = 0
# # print('********',len(lines))
# OrderID['OrderID']=OrderID['OrderID'].astype(str)
# # print(OrderID['OrderID'].dtypes)
# # print(OrderID['OrderID'])
# # print(type(OrderID))


# print('*******************')
# for i in range (1,len(OrderID)):      # OrderID是优先文件
#     for j in range (len(lines)):    # 对于列表list_timestamp遍历该列表找其中时间最小的  lins是gps文件
#         if(list_OrderID[j] == OrderID['OrderID'][i]):
#             isFind = 1;
#             if min_time > int(list_timestamp[j]):
#                 min_time = int(list_timestamp[j])
#                 index = j           #这一步就是记录list_timestamp中时间最小的在列表的第几个位置
#     if isFind==1:
#         # print("时间最小的是:", list_DriverID[index], list_OrderID[index], list_timestamp[index],
#         #       list_longitude[index], list_dimensionality[index])
#         datas = [[list_DriverID[index], list_OrderID[index], list_timestamp[index],
#                   list_longitude[index], list_dimensionality[index]]]
#         test = pd.DataFrame(data=datas)
#         test.to_csv('~/Downloads/Xianshi/Mintime.csv', mode='a', encoding='gbk', header=False, index=None, )
#     else:
#         print(OrderID['OrderID'][i],"没找到")
#     min_time = 999999999999
#     index = 0
#     isFind=0

#保存
# data.to_csv('~/Downloads/', sep=',', na_rep='', float_format=None,
#             columns=['DriverID', 'OrderID', 'timestamp','longitude','dimensionality','time'],
#             header=True, index=True,index_label=None, mode='w', encoding=None, compression=None,
#             quoting=None, quotechar='"',line_terminator='\n', chunksize=None, date_format=None,
#             doublequote=True,escapechar=None, decimal='.')
